package life.huangzhi.community.community.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @date 2019/12/7 13:58
 */
@Data
public class PaginationDTO {
    private List<QuestionDTO> questions;
    /**是否有上一页按钮*/
    private boolean showPrevious;
    /**是否有首页按钮*/
    private boolean showFirstPage;
    /** 是否有下一个*/
    private boolean showNext;
    /** 是否有展示末页*/
    private boolean showEndPage;
    /**当前页*/
    private Integer page;
    /**当前显示的页码*/
    private List<Integer> pages = new ArrayList<>();
    private Integer pageCount;
    private Integer pageSize;
    private Integer questionCount;
    public void setPagination (Integer pageCount, Integer page,Integer pageSize,Integer questionCount) {
        this.pageCount = pageCount;
        this.pageSize = pageSize;
        this.questionCount = questionCount;
        //分页展示界面逻辑
        pages.add(page);
        for (int i = 1; i <=3 ; i++) {
            if (page-i>0){
                pages.add(0,page - i);
            }
            if(page+i<=pageCount){
                pages.add(page + i);
            }
        }
        if(page < 1){
            page=1;
        }
        if(page>pageCount){
            page=pageCount;
        }
        this.page = page;
        //当前是第一页就不显示上一页按钮
        if(page==1){
            showPrevious = false;
        }else {
            showPrevious = true;
        }
        //当前尾页就不显示下一页按钮
        if(page .equals(pageCount)){
            showNext = false;
        }else {
            showNext = true;
        }

        //是否展示首页
        if(pages.contains(1)){
            showFirstPage = false;
        }else {
            showFirstPage = true;
        }
        //是否展示末页
        if(pages.contains(pageCount)){
            showEndPage = false;
        }else {
            showEndPage = true;
        }
    }
}
